/* api */
import { getPageInfo } from '@src/api/ProductV2Api'
/* entity */
import ProductCatalog, { ProductCatalogType } from '@model/entity/ProductCatalog'
/* hooks */
import { useFetchResult } from '@hooks/useFetch'
/* model */
import { getProductCatalogInfoSearchModel } from '@model/param/in/ProductCatalog'
/* vue */
import { computed, ComputedRef, ref, Ref } from 'vue'
/* util */
import { isEmpty } from '@src/util/type'

interface pageInfoResult {
  catalogInfo: ProductCatalog
}

export function useProductCatalogInfoFetch(params: getProductCatalogInfoSearchModel): Promise<ProductCatalogType> {
  let [data, callback] = useFetchResult<getProductCatalogInfoSearchModel, pageInfoResult>(async (getProductCatalogInfoParams: getProductCatalogInfoSearchModel) => {
    // return getProductCatalogInfo(getProductCatalogInfoParams)
    return getPageInfo(getProductCatalogInfoParams)
  }, params)
  
  return callback().then(() => {
    return data.value?.catalogInfo
  })
}

export function useProductCatalogInfoFetchParams(id: string | number): ComputedRef<getProductCatalogInfoSearchModel> {  
  return computed(() => ({ id }))
}

export function useProductCatalogEmpty(productCatalog: Ref<ProductCatalogType>): ComputedRef<boolean> {
  return computed<boolean>(() => isEmpty(productCatalog.value))
}